# /**
# * Copyright (c) 2022 Beijing Jiaotong University
# * PhotLab is licensed under [Open Source License].
# * You can use this software according to the terms and conditions of the [Open Source License].
# *
# * You may obtain a copy of [Open Source License] at: [https://open.source.license/]
# *
# * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# *
# * See the [Open Source License] for more details.
# */
# /**
# * Author: Shihao Xie
# * Created: Apr. 25, 2023
# * Supported by: National Key Research and Development Program of China
# */

import re

def underline_to_camel(name: str) -> str:
    # Underline turn to Camel
    return re.sub(r'(_[a-z])', lambda x: x.group(1)[1].upper(), name)


def camel_to_underline(name: str) -> str:
    # Camel turn to Underline
    if '_' not in name:
        name = re.sub(r'([a-z])([A-Z])', r'\1_\2', name)
    else:
        raise ValueError("Character '{}' contains underline and cannot be converted".format(name))
    return name.lower()